#Rem
Header: AGFX Framework. 
#End

#Rem
summary:  Bezier class
#End
Class TBezier
	
	#Rem
	summary:  bezier node points array
	#End
	Field points#[]
	
	#Rem
	summary:  bezier nodes points count
	#End
	Field inc#
	
	#Rem
	summary:  Constructor
	Create bezier from user defined points [Ax,Ay,cAx,cAy,Bx,By,cBx,cBy]
	[code]
		Local point:Float[8] = New Float[8]
		' point A[x,y]
		point[0] = ...
		point[1] = ... 
		
		' control point A[x,y]
		point[2] = ...
		point[3] = ...
		
		' point B[x,y]
		point[4] = ...
		point[5] = ...
		
		' control point B[x,y]
		point[6] = ...
		point[7] = ...
		
		Local bezier:TBezier = New TBezier(point)		
		
	[/code]
	if inc is not given, make a guess based on the distance between the two end points
	#End
	Method New(points#[],inc#=-1)
		Self.points = points
		
		If inc=-1	
			Local dx#=points[6]-points[0]
			Local dy#=points[7]-points[1]
			Local d#=Sqrt(dx*dx+dy*dy)
			inc=1/d
		Endif
		Self.inc = inc
	End
	
	#Rem
	summary:  get X value from bezier on [t] position
	work out the x co-ordinate of the point on the curve corresponding to the given value of t
	#End
	Method xpos#(t#)
		
		Local nt#=1-t
		Return nt*nt*nt*points[0] + 3*nt*nt*t*points[2] + 3*nt*t*t*points[4] + t*t*t*points[6]
	End Method
	
	#Rem
	summary:  get Y value from besiet on [t] position
	work out the y co-ordinate of the point on the curve corresponding to the given value of t
	#End
	Method ypos#(t#)
		
		Local nt#=1-t
		Return nt*nt*nt*points[1] + 3*nt*nt*t*points[3] + 3*nt*t*t*points[5] + t*t*t*points[7]
	End Method
	
End

#Rem
Footer: -------------------. 
#End